//
//  SVPProgressHUDEncapsulation.m
//  MrjStrong
//
//  Created by 肖会军 on 16/4/7.
//  Copyright © 2016年 excenon. All rights reserved.
//

#import "MrjSVProgressHUD.h"
#import <SVProgressHUD.h>

/**
 *  判断超时
 */
static BOOL isShowHUD = NO;

/**
 *  默认超时时间
 */
static NSTimeInterval minimumDismissTime = 10;

@implementation MrjSVProgressHUD

+ (void)setMinimumDismissTimeInterval:(NSTimeInterval)timeInterval
{
    [SVProgressHUD setMinimumDismissTimeInterval:timeInterval];
}

+(void)SVProgressHUDStyleDark
{
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleLight];
}

+(void)SVProgressHUDStyleLight
{
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleLight];
}

+(void)SVProgressHUDMaskTypeClear
{
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
}
+(void)SVProgressHUDMaskTypeBlack
{
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
}

+(void)show
{
    [MrjSVProgressHUD showWithStatus:@""];
}

+ (void)showOnlyMsg:(NSString *)msg{
    isShowHUD = NO;
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD setMaximumDismissTimeInterval:1];
    [SVProgressHUD showInfoWithStatus:msg];
    [SVProgressHUD showImage:[UIImage imageNamed:@""] status:msg];
}

+ (void)showWarningMsg:(NSString *)msg{
    isShowHUD = NO;
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD setMaximumDismissTimeInterval:1];
    [SVProgressHUD showInfoWithStatus:msg];
}

+ (void)showWithStatus:(NSString*)status
{
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeNative];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    [SVProgressHUD setMinimumSize:CGSizeMake(170, 110)];
    [SVProgressHUD showWithStatus:status];
    isShowHUD = YES;
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(minimumDismissTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        if (isShowHUD) {
//            isShowHUD = NO;
//            [MrjSVProgressHUD showErrorWithStatus:@"操作超时"];
//        }
//    });
}

+(void) showWithStatus:(NSString *)status withTimeout:(NSInteger)timeout
{
//    isShowHUD = YES;
//    [MrjSVProgressHUD showWithStatus:status];
//
//    if (timeout < 0) {
//        timeout = minimumDismissTime;
//    }
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(timeout * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        if (isShowHUD) {
//            isShowHUD = NO;
//            [MrjSVProgressHUD showErrorWithStatus:@"操作超时"];
//        }
//    });
}

+ (void)showSuccessWithStatus:(NSString*)status
{
    isShowHUD = NO;
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeNative];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    [SVProgressHUD setMinimumSize:CGSizeMake(170, 110)];
    [SVProgressHUD setImageViewSize:CGSizeMake(40, 40)];
    [SVProgressHUD setMaximumDismissTimeInterval:1];

    [SVProgressHUD showSuccessWithStatus:status];
}

+ (void)showErrorWithStatus:(NSString*)status
{
    isShowHUD = NO;
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeNative];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    [SVProgressHUD setMinimumSize:CGSizeMake(170, 110)];
    [SVProgressHUD setImageViewSize:CGSizeMake(40, 40)];
    [SVProgressHUD setMaximumDismissTimeInterval:1];

    [SVProgressHUD showErrorWithStatus:status];
}

+(void)dismiss
{
    isShowHUD = NO;
    [SVProgressHUD dismiss];
}
+ (void)dismissWithDelay:(NSTimeInterval)delay
{
    isShowHUD = NO;
    [SVProgressHUD dismissWithDelay:delay];
}

@end
